x`<template>
  <h1>房间信息</h1>
  <el-row :gutter="10">

    <el-col :span="6">
      <el-select v-model="query.RoomData.type"
                 :clearable="true"
                 placeholder="请选择部门">
        <el-option v-for="item in types.data"
                   :key="item.type"
                   :label="item.typeName"
                   :value="item.type" />
      </el-select>
    </el-col>

    <el-col :span="6">
      <el-button type="primary" @click="getRoomData(query.RoomData)">搜索</el-button>
    </el-col>

  </el-row>
  <el-table :data="tableData.data" style="width: 100%;margin-top: 20px">

    <el-table-column label="序号" type="index" width="80" align="center">
    </el-table-column>

    <el-table-column label="房间名称" prop="roomName" width="180" align="center">
    </el-table-column>

    <el-table-column label="房间类型" prop="typeName" width="100" align="center">
    </el-table-column>

    <el-table-column label="医生" prop="doctorName" width="100" align="center">
    </el-table-column>

    <el-table-column label="科室" prop="departmentName" width="100" align="center">
    </el-table-column>

    <el-table-column label="房间号" prop="roomNumber" width="100" align="center">
    </el-table-column>

    <el-table-column label="房间位置" prop="address" width="300 " align="center">
    </el-table-column>


    <el-table-column label="操作" width="200px" align="center">
      <template #default="scope">
        <el-button
          style="width: 60px;"
          size="small"
          @click="handleEdit(scope.row)"
        >修改
        </el-button>
        <el-button
          style="width: 60px;"
          size="small"
          type="danger"
          v-model:current-page="query.RoomData.pages"
          v-model:age-sizes="query.RoomData.size"
          @click="handleDelete(scope.row)"
        >删除
        </el-button
        >
      </template>
    </el-table-column>
  </el-table>
  <!--分页组件-->
  <div>
    <el-pagination
      small
      layout="total, prev, pager, next, jumper"
      :total="tableData.total"
      class="pagiantion "
      @current-change="pageChange"
      v-model:current-page="query.RoomData.pages"
      v-model:page-size="query.RoomData.size"
    />
  </div>
</template>

<script lang="js" setup>
import { onMounted, reactive } from "vue";
import { deleteRoomById, getRoom, getRoomType } from "@/utils/RoomRequest";
import { ElMessage, ElMessageBox } from "element-plus";
import { useRouter } from "vue-router";
import { getMedicineType } from "@/utils/MedicineRequest";

const router = useRouter();
//展示数据
const tableData = reactive({
  data: [],
  total: 0,
  current: 1, //当前页数
  size: 2  //每页显示几条数据
});
const departments = reactive({
  data: [
    {
      departmentName: "骨科",
      departmentId: "0"
    },
    {
      departmentName: "皮肤科",
      departmentId: "1"
    },
    {
      departmentName: "内科",
      departmentId: "2"
    }
  ]
});
//请求参数
const query = reactive({
  RoomData: {
    "address": "",
    "type": "",
    "doctorId": "",
    "roomId": "",
    "roomName": "",
    "roomNumber":"0",
    "size": tableData.size,
    "pages": tableData.current,
    "createTime": "",
    "updateTime": ""
  }
});
const types = reactive({
  data: []
});

//组件加载时触发
onMounted(() => {
  getRoomData(query.RoomData);
  getTypeOptionData();
});

const getTypeOptionData = async () => {
  let res = await getRoomType();
  types.data = res.data;
};

//获取数据
const getRoomData = async (requestData) => {
  let res = await getRoom(requestData);
  tableData.data = res.data;
  tableData.total = res.total;
  tableData.current = res.current;
};

//分页的页码变化时触发
const pageChange = () => {
  getRoomData(query.RoomData);
};

//修改回调
const handleEdit = (row) => {
  router.push({
    path:'/home/updateRoom',
    query:{id:row.roomId}
  })
};

//删除
const handleDelete = (row) => {
  ElMessageBox.confirm(
    "确定要删除吗?",
    "警告",
    {
      confirmButtonText: "确定",
      cancelButtonText: "取消",
      type: "warning"
    }
  )
    .then(async () => {
      let res = await deleteRoomById(row.roomId);
      if (res.data) {
        ElMessage({
          type: "success",
          message: "删除成功"
        });
      } else {
        ElMessage({
          type: "error",
          message: "删除成功"
        });
      }
      getRoomData(query.RoomData);

    })
    .catch(() => {
      ElMessage({
        type: "info",
        message: "取消删除"
      });
    });
};

</script>

<style scoped>
</style>